<div id="stu_grade_pie_chart"></div>
<div id="politic_and_outlook_chart"></div>
<div id="admission_pass_chart"></div>
<script>
    layui.use(['admin', 'config'], function () {
        let admin = layui.admin;

        function getGradeCount(startScore, endScore) {
            let data = {
                startScore: startScore,
                endScore: endScore
            }
            let count = 0;
            admin.req('api-firebird/fireBird/getGradeCount', JSON.stringify(data), function (res) {
                count = res.data;
                console.log(count);
            }, 'POST');
            return count;
        }

        function phyExmConChart() {
            let count = [];
            admin.req('api-firebird/fireBird/setPhyExmConChart', {}, function (res) {
                count = res.data;
                console.log(count);
            }, 'GET');
            return count;
        }

        function admissionPassChart() {
            let data = [];
            admin.req('api-firebird/fireBird/setAdmissionPassChart', {}, function (res) {
                data = res.data;
                console.log(data);
            }, 'GET');
            return data;
        }

        function pieChart(title, type, seriesName, data, pointFormat) {
            let pieOptions = {
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    type: type
                },
                title: {
                    text: title
                },
                tooltip: {
                    pointFormat: pointFormat ? '{series.name}: <b>'+pointFormat+'</b>' : '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                            style: {
                                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                            }
                        }
                    }
                },
                series: [{
                    name: seriesName,
                    colorByPoint: true,
                    data: data
                }],
                credits: {
                    enabled: false // 禁用版权信息
                }
            }
            return pieOptions;
        }

        Highcharts.chart('stu_grade_pie_chart', pieChart('考生成绩分数段饼状图', 'pie', '占比', [
            {
                name: '<400',
                y: getGradeCount(0, 400),
            },
            {
                name: '400~450',
                y: getGradeCount(400, 450),
            },
            {
                name: '450~500',
                y: getGradeCount(450, 500),
            },
            {
                name: '>500',
                y: getGradeCount(500),
            }
        ]));
        Highcharts.chart('politic_and_outlook_chart', pieChart('考生体检结论饼状图', 'pie', '占比', phyExmConChart()));
        Highcharts.chart('admission_pass_chart', pieChart('录取及格饼状图', 'pie', '占比', admissionPassChart()));
    })
</script>